/*
 * Copyright (C) 2004, Velocityme Partnership
 * ChangeStateActionForm.java
 *
 * Created on 05 September 2004, 05:21
 */

package com.velocityme.www.actionforms;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;

/**
 *
 * @author  Robert
 */
public class ChangeStateActionForm extends ActionForm {
    
    private Integer m_transitionId;
    private String m_message;
    private byte m_percentageComplete;
    private boolean m_assignTime;
    private int m_stateId;
    private int m_year;
    private int m_month;
    private int m_day;
    private int m_startHour;
    private int m_startMinute;
    private int m_stopHour;
    private int m_stopMinute;
    private int m_durationDays;
    private int m_durationHours;
    private int m_durationMins;
    private FormFile m_file;
        
    /** Creates a new instance of ChangeStateActionForm */
    public ChangeStateActionForm() {
    }
    
    public Integer getTransitionId() { return m_transitionId; }
    
    public void setTransitionId(Integer transitionId) { m_transitionId = transitionId; }
    
    public String getMessage() { return m_message; }
    
    public void setMessage(String message) { m_message = message; }
    
    public byte getPercentageComplete() { return m_percentageComplete; }
    
    public void setPercentageComplete(byte percentageComplete) { m_percentageComplete = percentageComplete; }
    
    public boolean getAssignTime() { return m_assignTime; }
    
    public void setAssignTime(boolean assignTime) { m_assignTime = assignTime; }
    
    public int getStateId() { return m_stateId; }
    
    public void setStateId(int stateId) { m_stateId = stateId; }
    
    public int getYear() { return m_year; }
    
    public void setYear(int year) { m_year = year; }
    
    public int getMonth() { return m_month; }
    
    public void setMonth(int month) { m_month = month; }
    
    public int getDay() { return m_day; }
    
    public void setDay(int day) { m_day = day; }
    
    public int getStartHour() { return m_startHour; }
    
    public void setStartHour(int startHour) { m_startHour = startHour; }
    
    public int getStartMinute() { return m_startMinute; }
    
    public void setStartMinute(int startMinute) { m_startMinute = startMinute; }
    
    public int getStopHour() { return m_stopHour; }
    
    public void setStopHour(int stopHour) { m_stopHour = stopHour; }
    
    public int getStopMinute() { return m_stopMinute; }
    
    public void setStopMinute(int stopMinute) { m_stopMinute = stopMinute; }
    
    public int getDurationDays() { return m_durationDays; }
    
    public void setDurationDays(int durationDays) { m_durationDays = durationDays; }
    
    public int getDurationHours() { return m_durationHours; }
    
    public void setDurationHours(int durationHours) { m_durationHours = durationHours; }
    
    public int getDurationMins() { return m_durationMins; }
    
    public void setDurationMins(int durationMins) { m_durationMins = durationMins; }
    
    public int getDurationTotalMins() {
        return m_durationDays * 8 * 60 + m_durationHours * 60 + m_durationMins;
    }
    
    public void setDurationTotalMins(int totalMins) {
        m_durationDays = totalMins / (8 * 60);
        m_durationHours = (totalMins / 60) % 8;
        m_durationMins = totalMins % 60;
    }
    
    public FormFile getFile() { return m_file; }
    
    public void setFile(FormFile file) { m_file = file; }
    
    /**
     * Check to make sure the client hasn't exceeded the maximum allowed upload size inside of this
     * validate method.
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = null;
        //has the maximum length been exceeded?
        Boolean maxLengthExceeded = (Boolean)request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
        if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue())) {
            errors = new ActionErrors();
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.file.maxLengthExceeded"));
            errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.file.maxLengthExplanation"));
        }
        return errors;
    }
}
